Kubernetes : Use Persistent Storage
2015/12/21 |
It's necessary to use external storage if you'd like to use Persistent Data.
|
|
For exmaple, Create a Pod with mounting external storage which is mapped with a directory for saving data on the Node Pod runs.
The environment and Container image on this exmaple are the same with here.
|
|
[1] | Create a Pod on Admin Node. |
[root@dlp ~]#
vi pod-webserver.yaml apiVersion: v1 kind: Pod metadata: name: httpd spec: containers: - name: httpd image: web_server ports: - containerPort: 80 volumeMounts: # the volume to use (it's the one defined in "volumes" section) - name: httpd-storage # mount point inside Container mountPath: /var/www/html volumes: # any name you like - name: httpd-storage hostPath: # the directory on Host Node for saving data path: /var/docker/disk01
[root@dlp ~]#
[root@dlp ~]# kubectl create -f pod-webserver.yaml pods/httpd kubectl get pods -o wide NAME READY STATUS RESTARTS AGE NODE httpd 0/1 Running 0 8s node01[root@dlp ~]# kubectl get pod httpd -o yaml | grep "podIP" podIP: 172.16.89.7 |
[2] | Move to a Node that Pod is running and make sure to work normally. |
[root@node01 ~]# echo "Persistent Storage" > /var/docker/disk01/index.html [root@node01 ~]# curl http://172.16.89.7/ Persistent Storage |